Don't leak memory when realloc fails.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 7 Sep 2005 19:13:38 +0000 (19:13 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 7 Sep 2005 19:13:38 +0000 (19:13 +0000)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/console/daemon/io.c

index 1bcdfdf04dc2f3b40ed529604cb2bed1aaf2f813..8f8f50ceee6d12577d27b264a8b4b826ce05d118 100644 (file)
@@ -279,6 +279,7 @@ static bool watch_domain(struct domain *dom, bool watch)
 static struct domain *create_domain(int domid)
 {
        struct domain *dom;
+       char *s;
 
        dom = (struct domain *)malloc(sizeof(struct domain));
        if (dom == NULL) {
@@ -306,10 +307,11 @@ static struct domain *create_domain(int domid)
        dom->conspath = xs_get_domain_path(xs, dom->domid);
        if (dom->conspath == NULL)
                goto out;
-       dom->conspath = realloc(dom->conspath, strlen(dom->conspath) +
-                               strlen("/console") + 1);
-       if (dom->conspath == NULL)
+       s = realloc(dom->conspath, strlen(dom->conspath) +
+                   strlen("/console") + 1);
+       if (s == NULL)
                goto out;
+       dom->conspath = s;
        strcat(dom->conspath, "/console");
 
        if (!watch_domain(dom, true))